﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class CreateDiscussion : System.Web.UI.Page
{

    //checked if Title is there
    //do the participants thingi
    //get the toggle
    // first comment - auto expand

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {
            username.InnerText = Session["username"].ToString();
        }
        //using (var dbcontext = new iKonnectDevDBEntities())
        //{
        //    Member member = dbcontext.Members.First(i => i.MemberID == Convert.ToInt32(ownerId.Value));
        //    username.InnerText = member.FullName;
        //}
    }

    protected void Submit_Button(object sender, EventArgs e)
    {
        // there was another way, this one doesn't change the url,,, btw, any otehr differences?
        Server.Transfer("Test.aspx");
        

        using (var dbcontext = new iKonnectDevDBEntities())
        {
            //int ownerID = Convert.ToInt32(ownerId.Value);
            
            //#region creating the Discussion
            //Discussion newDiscussion = new Discussion()
            //{
            //    MemberID = ownerID,
            //    Title = title.Value,
            //    Timestamp = DateTime.Now,
            //    DiscussionType = discussionType.Checked
            //};
            //dbcontext.AddToDiscussions(newDiscussion);
            //int discussionID = ;// somehow get the ID
            //#endregion
 
            //#region creating the Discussionparticipants
            //DiscussionParticipant owenerDiscussionParticipant = new DiscussionParticipant()
            //{
            //    DiscussionID = ,
            //    MemberID = ownerID
            //};
            //dbcontext.AddToDiscussionParticipants(owenerDiscussionParticipant);
            ////loop over the participants somehow
            ////{
            //String participant = ; // get a participant at a time
            //DiscussionParticipant newDiscussionParticipant = new DiscussionParticipant()
            //{
            //    DiscussionID = discussionID,// the ID of the new discussion just added
            //    MemberID = participant
            //};
            //dbcontext.AddToDiscussionParticipants(newDiscussionParticipant);
            ////}
            //#endregion
 
            //#region DiscussionThread
            //DiscussionThread newThread = new DiscussionThread()
            //{
            //    DiscussionID = discussionID,
            //    MemberID = ownerID,
            //    Timestamp = DateTime.Now,
            //    Text = firstComment.Value,
            //    Attachment = null // for now :)
            //}; //we need to add attachments
            //dbcontext.AddToDiscussionThreads(newThread);
            //#endregion
            //dbcontext.SaveChanges();
        }
        

    }

}